package com.edz.from0507to0513apk.View;

import android.support.v4.hardware.fingerprint.FingerprintManagerCompat;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.edz.from0507to0513apk.Base.BaseActivity;
import com.edz.from0507to0513apk.R;

import butterknife.BindView;

public class AtyFingerprint extends BaseActivity {

    @BindView(R.id.btn_fingerprint)
    Button btn_fingerprint;

    private static final String TAG = "AtyFingerprint";
    private FingerprintManagerCompat fingerprintManagerCompat;

    @Override
    protected void initView() {
    }

    @Override
    protected void initData() {
        fingerprintManagerCompat = FingerprintManagerCompat.from(this);
    }

    @Override
    protected void setEvent() {
        btn_fingerprint.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fingerprintManagerCompat.authenticate(null, 0, null, new MyCallBack(), null);
            }
        });
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_round_dialog;
    }

    private class MyCallBack extends FingerprintManagerCompat.AuthenticationCallback {
        private static final String TAG = "MyCallBack";

        /**
         * 出现错误的时候回调次函数
         *
         * @param errMsgId
         * @param errString
         */
        @Override
        public void onAuthenticationError(int errMsgId, CharSequence errString) {
            super.onAuthenticationError(errMsgId, errString);
            Log.e(TAG, "onAuthenticationError ==== >" + "errMsgId" + errMsgId + "msg ===" +
                    errString);
        }

        /**
         * 验证失败的时候回调
         */
        @Override
        public void onAuthenticationFailed() {
            super.onAuthenticationFailed();
            Log.e(TAG, "onAuthenticationFailed ====");
        }

        /**
         * 验证成功回调
         *
         * @param result
         */
        @Override
        public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult
                                                              result) {
            super.onAuthenticationSucceeded(result);
            Log.e(TAG, "onAuthenticationSucceeded ====" + result);
        }

        /**
         * @param helpMsgId
         * @param helpString
         */
        @Override
        public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
            super.onAuthenticationHelp(helpMsgId, helpString);
            Log.e(TAG, "onAuthenticationHelp ====" + helpMsgId + "====" + helpString);
        }
    }
}
